Skip to content

feat: add postdownload script support for agent types#2573

Merged
vjripoll merged 5 commits into
mainfrom
vripoll/add-new-postdownload-script-execution
Jun 19, 2026
Merged

feat: add postdownload script support for agent types#2573
vjripoll merged 5 commits into
mainfrom
vripoll/add-new-postdownload-script-execution

Conversation

@vjripoll

@vjripoll vjripoll commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements post-download hook functionality that executes custom scripts after OCI package extraction. This enables packages to perform installation steps, validations, and system configuration that cannot be handled through simple file extraction.

Changes

Core Implementation:

  • Added PostDownloadHook struct with path, args, and env fields in package.rs and rendered.rs
  • Added post_download_hook: Option<PostDownloadHook> to Package struct
  • Created PostDownloadHookExecutor to handle hook execution with proper error handling and timeouts
  • Integrated post-download hook execution into OCIPackageManager.install() workflow

Hook Execution:

  • Two-part execution model: path = interpreter/command, args[0] = script path, args[1..] = script arguments
  • Environment variable support with template variable rendering
  • Fixed 300s timeout for hook execution
  • Unix: Auto-chmod scripts to 0755 before execution if needed
  • Comprehensive error handling for missing commands, execution failures, and timeouts

Agent Type Structure:

deployment:
  packages:
    infra-agent:
      download:
        oci:
          repository: newrelic/infrastructure-bundle
          version: ${nr-var:version}
      post_download_hook:
        path: "/bin/bash"
        args:
          - "bin/install.sh"
          - "--mode=verify"
        env:
          env_vars: "vars"
  • Happy path
Jun 10 17:30:48 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[316521]: {"timestamp":"2026-06-10T17:30:48","level":"DEBUG","message":"Postdownload hook found for package ebpf-agent","span":{"id":"ebpf","name":"start_agent"},"spans":[{"id":"ebpf","name":"start_agent"}]}
Jun 10 17:30:48 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[316521]: {"timestamp":"2026-06-10T17:30:48","level":"DEBUG","message":"Executing postdownload","command":"/bin/bash","script":"postdownload.sh","args":"[]","timeout":"300s","span":{"id":"ebpf","name":"start_agent"},"spans":[{"id":"ebpf","name":"start_agent"}]}
Jun 10 17:30:48 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[316521]: {"timestamp":"2026-06-10T17:30:48","level":"DEBUG","message":"Postdownload completed successfully for package ebpf-agent","span":{"id":"ebpf","name":"start_agent"},"spans":[{"id":"ebpf","name":"start_agent"}]}
Jun 10 17:30:48 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[316521]: {"timestamp":"2026-06-10T17:30:48","level":"DEBUG","message":"agent version successfully checked","span":{"id":"ebpf","name":"version_check"},"spans":[{"id":"ebpf","name":"start_agent"},{"id":"ebpf","name":"version_check"}]}
Jun 10 17:30:48 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[316521]: {"timestamp":"2026-06-10T17:30:48","level":"DEBUG","message":"Agent is healthy","span":{"id":"ebpf","name":"process_event"},"spans":[{"id":"ebpf","name":"process_event"}]}
  • Error if command or path to the scripts are not in agent type
Jun 10 18:17:20 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[336765]: {"timestamp":"2026-06-10T18:17:20","level":"WARN","message":"Agent is unhealthy","status":"","last_error":"effective agent cannot be assembled from YAML config: error assembling agents: error parsing oci reference: postdownload args must have at least 2 elements: command and script path","span":{"id":"ebpf","name":"process_event"},"spans":[{"id":"ebpf","name":"process_event"}]}
  • Error dependecy not found
Jun 11 10:02:35 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[499201]: {"timestamp":"2026-06-11T10:02:35","level":"WARN","command":"/bin/bash","error":"Postdownload failed with exit code Some(18)\nstderr: [ERROR] Linux headers for kernel 6.14.0-27-generic not found at /lib/modules/6.14.0-27-generic/build. Please install them for the eBPF Agent to work.\n","span":{"id":"ebpf","name":"start_agent"},"spans":[{"id":"ebpf","name":"start_agent"}]}
Jun 11 10:02:35 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[499201]: {"timestamp":"2026-06-11T10:02:35","level":"ERROR","message":"Failed to start supervisor: package installation failed: failure installing package: 'ebpf-agent': error attempting to install OCI artifact: Postdownload script failed: Postdownload script execution failed: Postdownload failed with exit code Some(18)\nstderr: [ERROR] Linux headers for kernel 6.14.0-27-generic not found at /lib/modules/6.14.0-27-generic/build. Please install them for the eBPF Agent to work.\n","span":{"id":"ebpf","name":"start_agent"},"spans":[{"id":"ebpf","name":"start_agent"}]}
Jun 11 10:02:35 ubuntu-gnu-linux-24-04-3 newrelic-agent-control[499201]: {"timestamp":"2026-06-11T10:02:35","level":"WARN","message":"Agent is unhealthy","status":"","last_error":"could not start the supervisor: package installation failed: failure installing package: 'ebpf-agent': error attempting to install OCI artifact: Postdownload script failed: Postdownload script execution failed: Postdownload failed with exit code Some(18)\nstderr: [ERROR] Linux headers for kernel 6.14.0-27-generic not found at /lib/modules/6.14.0-27-generic/build. Please install them for the eBPF Agent to work.\n","span":{"id":"ebpf","name":"process_event"},"spans":[{"id":"ebpf","name":"process_event"}]}
image

@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch 10 times, most recently from a96a838 to 29f1bee Compare June 8, 2026 13:35
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch 20 times, most recently from afcae14 to db6b9b3 Compare June 11, 2026 08:34
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch from 5896d6a to dbcaa9f Compare June 18, 2026 10:23
Comment thread agent-control/src/agent_type/runtime_config/on_host/package.rs Outdated
Comment thread agent-control/src/agent_type/runtime_config/on_host/package.rs Outdated
Comment thread docs/INTEGRATING_AGENTS.md
Comment thread agent-control/src/agent_type/runtime_config/on_host/package.rs Outdated
Comment thread agent-control/src/package/post_download_hook_executor.rs Outdated
Comment thread agent-control/src/package/post_download_hook_executor.rs Outdated
Comment thread agent-control/src/package/post_download_hook_executor.rs Outdated
Comment thread agent-control/src/agent_type/runtime_config/on_host/package.rs
Comment thread docs/INTEGRATING_AGENTS.md Outdated
Comment thread agent-control/src/package/post_download_hook_executor.rs
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch 3 times, most recently from 29234fe to 69e4025 Compare June 19, 2026 06:24
Comment thread agent-control/src/agent_type/runtime_config/on_host/package/rendered.rs Outdated
Comment thread agent-control/src/agent_type/runtime_config/on_host/package.rs Outdated
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch from 69e4025 to 46bd05d Compare June 19, 2026 07:16
Comment thread CHANGELOG.md Outdated
pub struct PostDownloadHook {
/// Absolute path to the command/executable (e.g., "/bin/bash", "/usr/bin/python3")
pub path: String,
/// Arguments where first element is the script path, followed by additional arguments.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align documentation with the other PostDownloadHook type:

Suggested change
/// Arguments where first element is the script path, followed by additional arguments.
/// Arguments passed to the executable on [`path`].

@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch from 46bd05d to 56c6e3e Compare June 19, 2026 08:05
Comment thread agent-control/src/package/post_download_hook_executor.rs Outdated
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch from 56c6e3e to 8d9d29e Compare June 19, 2026 12:00
danielorihuela
danielorihuela previously approved these changes Jun 19, 2026
@vjripoll vjripoll force-pushed the vripoll/add-new-postdownload-script-execution branch from 8d9d29e to bce13a6 Compare June 19, 2026 13:36

@DavSanchez DavSanchez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

Comment on lines +49 to +51
pub fn new(package_dir: PathBuf) -> Self {
Self { package_dir }
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not to fix here, but this could have been a From implementation!

@vjripoll vjripoll merged commit b54d1c9 into main Jun 19, 2026
34 checks passed
@vjripoll vjripoll deleted the vripoll/add-new-postdownload-script-execution branch June 19, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants